package main

import (
	"fmt"
	"sync"
)

func main() {
	wg := sync.WaitGroup{}
	ch := make(chan int, 10)
	for i := 0; i < 10; i++ {
		ch <- i
	}
	close(ch)
	wg.Add(4)
	for i := 0; i < 4; i++ {
		go func() {
			for {
				//task := <-ch  // 关闭channel之后还能从channel里取出为0的值
				if task, ok := <-ch; !ok {
					return
				} else {
					fmt.Println(task)
				}
			}
			wg.Done()
		}()
	}
	wg.Wait()
}
